Repository navigation
[repo-assist] perf: avoid intermediate array allocation in toStrArray helpers - #488
Merged
sergey-tihon merged 1 commit intoSep 5, 2026
Conversation
Replace Array.map |> Array.toList with a single backward loop building the (name, str) list directly. This runs once per array-typed query/path/header parameter on the request-serialization hot path, avoiding the temporary array allocated by Array.map before conversion to a list. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is localized and preserves output order/behavior while reducing allocations in a well-scoped runtime helper.
Pull request overview
This PR optimizes request-serialization helpers in SwaggerProvider.Runtime by removing an intermediate array allocation when converting array-typed parameters into (name, value) lists for query/path/header serialization.
Changes:
- Replaced
Array.map |> Array.toListwith a single reverse-index loop that conses directly into an F# list fortoStrArray,toStrArrayDateTime, andtoStrArrayDateTimeOffset. - Preserved original element ordering by iterating from
Length - 1down to0.
File summaries
| File | Description |
|---|---|
| src/SwaggerProvider.Runtime/RuntimeHelpers.fs | Reworks array-to-(name, string) conversion helpers to avoid intermediate array allocation on the hot path. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
sergey-tihon
deleted the
repo-assist/perf-toStrArray-alloc-5af0f2fe495ea2cd
branch
September 5, 2026 15:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
What
Replaces
Array.map |> Array.toListwith a single backward loop that builds the(name, str)list directly intoStrArray,toStrArrayDateTime, andtoStrArrayDateTimeOffsetinRuntimeHelpers.fs.Why
These helpers are called once per array-typed query/path/header parameter on the request-serialization hot path (
toQueryParams/toParam). The previous implementation allocated an intermediate array viaArray.mapbefore converting it to a list viaArray.toList(a second full traversal + list allocation). The new version does a single reverse-order pass over the source array, consing directly onto an F# list, eliminating the intermediate array allocation and the extra traversal, while preserving the original element order.Trade-offs
None functionally — output order and values are identical. Slightly more verbose code (explicit loop vs. pipeline) in exchange for one fewer allocation per call.
Test Status
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
petstore.swagger.ioTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.
Add this agentic workflow to your repo
To install this agentic workflow, run